package model;

import java.awt.Image;
import java.util.ArrayList;

public class TileType 
{
	private int[][] connections;
	private String imageName;
	private Image image;
	
	public TileType (int[][] connections, String imageName)
	{
		this.connections = connections;
		this.imageName = imageName;
	}
	
	public int[] findConnection (int endpoint)
	{
		ArrayList<Integer> points = new ArrayList<Integer>();
		for (int[] connection:connections)
		{
			for (int end: connection)
			{
				if (end==endpoint)
				{
					for (int con: connection)
					{
						if (con!=endpoint && !points.contains(con))
						{
							points.add(con);
						}
					}
				}
			}
		}
		return convertToArray(points.toArray(new Integer[points.size()]));
	}
	
	private int[] convertToArray(Integer[] integers)
	{
		int[] array = new int[integers.length];
		for (int i=0; i<integers.length; i++)
		{
			array[i] = integers[i];
		}
		return array;
	}

	public int[][] getConnections() {
		return connections;
	}

	public void setEndpoints(int[][] endpoints) {
		this.connections = endpoints;
	}

	public String getImageName() {
		return imageName;
	}

	public void setImageName(String imageName) {
		this.imageName = imageName;
	}

	/**
	 * @return the image
	 */
	public Image getImage() {
		return image;
	}

	/**
	 * @param image the image to set
	 */
	public void setImage(Image image) {
		this.image = image;
	}
}
